package com.example.user.controller;

import com.example.user.domain.dto.LoginFormDTO;
import com.example.user.domain.vo.UserLoginVO;
import com.example.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Api(tags = "用户相关接口")
@RestController
@RequestMapping("/users")
@RequiredArgsConstructor
public class UserController {

    private final IUserService userService;

    @ApiOperation("用户登录接口")
    @PostMapping("login")
    public UserLoginVO login(@RequestBody @Validated LoginFormDTO loginFormDTO){
        return userService.login(loginFormDTO);
    }

    @ApiOperation("扣减余额")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pw", value = "支付密码"),
            @ApiImplicitParam(name = "amount", value = "支付金额")
    })
    @PutMapping("/money/deduct")
    public void deductMoney(@RequestParam("pw") String pw,@RequestParam("amount") Integer amount){
        userService.deductMoney(pw, amount);
    }

    /**
     * 根据用户ID获取用户基础信息（昵称、联系方式）
     * @param userId 用户ID
     * @return 基础信息Map（key: userName-昵称，phone-联系方式）
     */
    @GetMapping("basic-info")
    Map<String, String> getUserBasicInfo(@RequestParam("userId") Long userId) {
        Map userBasicInfo = new HashMap<>();
        userBasicInfo.put("userName", "张三");
        userBasicInfo.put("phone", "12345678901");

        return userBasicInfo;
    }

    /**
     * 根据用户ID集合批量获取用户基础信息
     * @param userIds 用户ID集合（逗号分隔，如"1001,1002"）
     * @return 键值对（key: userId，value: 基础信息Map）
     */
    @GetMapping("batch-basic-info")
    Map<Long, Map<String, String>> batchGetUserBasicInfo(@RequestParam("userIds") String userIds) {
        Map<Long, Map<String, String>> userBasicInfoMap = new HashMap<>();
        userBasicInfoMap.put(1001L, Map.of("userName", "张三", "phone", "12345678901"));
        userBasicInfoMap.put(1002L, Map.of("userName", "李四", "phone", "12345678902"));
        return userBasicInfoMap;
    }
}

